#!/usr/bin/env perl

use	strict;
use	warnings;

$| = 1;
$DEBUG = 0;

use constant LEFT_FIELD_NTH => 0;

my $dump_file = $ARGV[0];
my $urls_file = $ARGV[1];
die "\tUsage: $0 <sorted dump_file> <sorted urls-file>\n" unless $dump_file and $urls_file; 

open(FH_DUMP, $dump_file) or die "Fail to open $dump_file : $!\n";
open(FH_URLS, $urls_file) or die "Fail to open $urls_file : $!\n";

my	$url_current;
$url_current = <FH_URLS>;
chomp $url_current if $url_current;
while(<FH_DUMP>) {
	chomp;
	next unless $_;
	my	@f = split;
	my	$url = $f[ LEFT_FIELD_NTH ];
	next unless $url;

	if ($DEBUG) {
		print "---- $url <<< $url_current\n" if $url lt $url_current;
		print "==== $url === $url_current\n" if $url eq $url_current;
		print "---- $url >>> $url_current\n" if $url gt $url_current;
	}

	while ($url_current && ($url gt $url_current)) {
		$url_current = <FH_URLS>;
		chomp $url_current if $url_current;
		last unless $url_current;

		if ($DEBUG) {
			print "---- $url <<< $url_current\n" if $url lt $url_current;
			print "==== $url === $url_current\n" if $url eq $url_current;
			print "---- $url >>> $url_current\n" if $url gt $url_current;
		}
	}
	last unless $url_current;

	print "$_\n" if $url_current and $url eq $url_current;
}

close(FH_URLS);
close(FH_DUMP);

exit(0);
